package cn.iocoder.yudao.module.system.service.wework;

import cn.iocoder.yudao.framework.common.pojo.wework.WeworkMessageSendReq;
import cn.iocoder.yudao.framework.common.pojo.wework.WeworkMessageSendResponse;
import cn.iocoder.yudao.framework.common.util.string.StrUtils;
import cn.iocoder.yudao.module.system.util.NotifyUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTIFY_SEND_WEWORK;

/**
 * 发送企业微信消息实现类
 * @author hanjiale
 */
@Service
@Slf4j
public class WeworkSmsSendServiceImpl implements WeworkSmsSendService{

    @Override
    public String sendSingleSmsToUser(WeworkMessageSendReq req) {
        String toUser = req.getTouser();
        if (StringUtils.isBlank(toUser)){
            throw exception(NOTIFY_SEND_WEWORK);
        }
        log.info("发送企业微信参数：" + req.toString());
        WeworkMessageSendResponse response = NotifyUtils.sendWeworkMessage(req);
        log.info("发送企业微信消息：" + response.toString());
        return response.getErrmsg();
    }
}
